package com.palm.hubo2o.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.palm.hubo2o.adapter.HisIssueAdapter;
import com.palm.hubo2o.event.IssueCountEvent;
import com.palm.hubo2o.ui.fragment.K3BT2Fragment;
import com.palm.hubo2o.ui.fragment.K3BT3Fragment;
import com.palm.hubo2o.ui.fragment.K3SumFragment;
import com.palm.hubo2o.ui.fragment.K3T3Fragment;
import com.palm.hubo2o.ui.fragment.K3TD2Fragment;
import com.palm.hubo2o.ui.fragment.K3TF2Fragment;
import com.palm.hubo2o.ui.fragment.LotteryFragment;
import com.palm.hubo2o.util.EnumCode;
import com.palm.palmutils.LayoutUtils;

/**
 * Created by dest1 on 2015/10/14.
 */
public class K3LotteryActivity extends LotteryActivity {
    private LotteryFragment k3Sum;
    private LotteryFragment k3_3bt;
    private LotteryFragment k3_3t;
    private LotteryFragment k3_2tf;
    private LotteryFragment k3_2td;
    private LotteryFragment k3_2bt;
    private HisIssueAdapter adapter;
    private TextView mCountView;

    @NonNull
    @Override
    protected EnumCode.gameId gameId() {
        return EnumCode.gameId.HBP3;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        k3Sum = new K3SumFragment();
        k3Sum.setTitle("和值");
        k3_3bt = new K3BT3Fragment();
        k3_3bt.setTitle("三不同号");
        k3_3t = new K3T3Fragment();
        k3_3t.setTitle("三同号");
        k3_2tf = new K3TF2Fragment();
        k3_2tf.setTitle("二同号复选");
        k3_2td = new K3TD2Fragment();
        k3_2td.setTitle("二同号单选");
        k3_2bt = new K3BT2Fragment();
        k3_2bt.setTitle("二不同号");
        setFragments(k3Sum, k3_3bt, k3_3t, k3_2tf, k3_2td, k3_2bt);
        mCountView = new TextView(this);
        int height = LayoutUtils.dp2pix(this, 30);
        mCountView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
        mCountView.setGravity(Gravity.CENTER_VERTICAL);
        addViewToDrawer(mCountView);

        handleLimitPick(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleLimitPick(intent);
    }

    private void handleLimitPick(Intent intent) {
        EnumCode.PlayType playType = (EnumCode.PlayType) intent.getSerializableExtra(EnumCode.PlayType.class.getName());
        if (playType != null) {
            switch (playType) {
                case K3_HZ:
                    vp.setEnabled(false);
                    tab.getTabAt(0).select();
                    tab.setVisibility(View.GONE);
                    break;
                case K3_3BT:
                    vp.setEnabled(false);
                    tab.getTabAt(1).select();
                    tab.setVisibility(View.GONE);
                    break;
                case K3_3THDX:
                case K3_3THTX:
                    vp.setEnabled(false);
                    tab.getTabAt(2).select();
                    tab.setVisibility(View.GONE);
                    break;
                case K3_2THFX:
                    vp.setEnabled(false);
                    tab.getTabAt(3).select();
                    tab.setVisibility(View.GONE);
                    break;
                case K3_2THDX:
                    vp.setEnabled(false);
                    tab.getTabAt(4).select();
                    tab.setVisibility(View.GONE);
                    break;
                case K3_2BT:
                    vp.setEnabled(false);
                    tab.getTabAt(5).select();
                    tab.setVisibility(View.GONE);
                    break;
                default:
                    break;
            }
        }
    }


    public void onEvent(IssueCountEvent event) {
        if (gameId() == event.gameId) {
//            mCountView.setText(TimeUtils.formatTime("mm:ss", new Date(event.timeLeft)));
        }
    }

}
